﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Linq;

namespace C1106KV
{
    partial interface T7
    {
        void Hide();
    }

    public class Student : IEnumerable, T7
    {
        public int StudentID { get; set; }
        public string StudentName { get; set; }
        public int? Mark { get; set; }
        string[] array = { "ahfadkjf", "adgsfhd", "jhkghj", "fhgdjhfj", "sdghdfjhj" };

        public Student(int id, string name, int? mark)
        {
            StudentID = id;
            StudentName = name;
            this.Mark = mark;
        }

        public Student() { }

        public override string ToString()
        {
            return StudentID + ": " + StudentName;
        }

        #region IEnumerable Members

        public IEnumerator GetEnumerator()
        {
            for (int i = 0; i < array.Length; i++)
            {
                yield return array[i];
            }
        }

        #endregion

        #region T7 Members

        public void Hide()
        {
            throw new NotImplementedException();
        }

        public void Show()
        {
            throw new NotImplementedException();
        }

        #endregion
    }

    class General<T> where T : Student
    {
        T[] arr;
        int index = 0;

        public General()
        {
            arr = new T[5];
        }

        public void Add(T t)
        {
            if (index < arr.Length)
            {
                arr[index] = t;
                index++;
            }
        }

        public void Display()
        {
            for (int i = 0; i < arr.Length; i++)
            {
                Console.WriteLine(arr[i]);
            }
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            //General<Student> obj = new General<Student>();
            //obj.Add(new Student(1,"ajfdsf"));
            //obj.Add(new Student(2,"fkjgkdfh"));
            //obj.Display();

            Student s = new Student(1, "gdhjg", null);
            int x = s.Mark ?? 10;
            if (s.Mark.HasValue)
            {
                Console.WriteLine(s.Mark.Value);
            }
            foreach (string value in s)
            {
                Console.WriteLine(value);
            }

            var student = new Student()
            {
                StudentID = 1,
                Mark = 10,
                StudentName = "C1106KV"
            };

            var collection = new List<Student>() {
                new Student(){StudentID= 1, StudentName="Name 1"}, 
                new Student(){StudentID=2, StudentName = "Name 2"}
            };

            var obj = collection.Select(st => new { 
                ID = st.StudentID, 
                Name = st.StudentName, 
                Desc = st.GetDetails() 
            }).ToList();

            var querry = from st in collection
                         orderby st.StudentID descending
                         select st;

            foreach (var item in querry)
            {
                Console.WriteLine(item.GetDetails());
            }

            foreach (var item in obj)
            {
                Console.WriteLine(item.Desc);
            }

            var xyz = new { ID = 1, Desc = "ajhfkjadf" };

            //Console.ReadLine();

        }
    }
}
